#include "sd_global.h"
int sd_KeyShortCompare(const sd_Key* k1, const sd_Key* k2)
{
	if (k1->keyval.shortkey < k2->keyval.shortkey)
		return -1;
	else if (k1->keyval.shortkey > k2->keyval.shortkey)
		return 1;
	else 
		return 0;
}

int sd_KeyIntCompare(const sd_Key* k1, const sd_Key* k2)
{
	if (k1->keyval.intkey < k2->keyval.intkey)
		return -1;
	else if (k1->keyval.intkey > k2->keyval.intkey)
		return 1;
	else 
		return 0; 
}

int sd_KeyCharCompare(const sd_Key* k1, const sd_Key* k2)
{
	return strcmp(k1->keyval.charkey, k2->keyval.charkey);
}

uint32 sd_KeyShortHashcode(const sd_Key* k)
{
	return (uint32)k->keyval.shortkey;
}

uint32 sd_KeyIntHashcode(const sd_Key* k)
{
	return (uint32)k->keyval.intkey;
}

uint32 sd_KeyCharHashcode(const sd_Key* k)
{
	uint32 sum=0;
	const char* p=k->keyval.charkey;
	while(*p) sum+=(uint32)(*p++);
	return sum;
}

void sd_KeyPrint(const sd_Key* k, FILE* fp)
{
	switch(k->type)
	{
	case SD_KEYTYPE_SHORT:
		fprintf(fp,"%d", (int)k->keyval.shortkey);
		break;
	case SD_KEYTYPE_INT:
		fprintf(fp,"%lld", k->keyval.intkey);
		break;
	case SD_KEYTYPE_VARCHAR:
		fprintf(fp,"%s",k->keyval.charkey);
		break;
	}
}
